package me.zhengjie.modules.website.repository;

import me.zhengjie.modules.website.domain.CmInfos;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List;

/**
 * @author system
 * @since 2025-01-21 15:57:52
 */
@Component
public class CmInfosSpecifications {

    public static Specification<CmInfos> queryList(CmInfos cmInfos) {
        return (root, query, builder) -> {
            List<Predicate> predicates = new ArrayList<>();
            if (cmInfos.getInfoId() != null) {
                predicates.add(builder.like(root.get("infoId" ).as(String.class), "%" + cmInfos.getInfoId() + "%" ));
            }
            if (cmInfos.getInfoTitle() != null) {
                predicates.add(builder.like(root.get("infoTitle" ).as(String.class), "%" + cmInfos.getInfoTitle() + "%" ));
            }
            if (cmInfos.getInfoDraftuserid() != null) {
                predicates.add(builder.like(root.get("infoDraftuserid" ).as(String.class), "%" + cmInfos.getInfoDraftuserid() + "%" ));
            }
            if (cmInfos.getInfoDraftusername() != null) {
                predicates.add(builder.like(root.get("infoDraftusername" ).as(String.class), "%" + cmInfos.getInfoDraftusername() + "%" ));
            }
            if (cmInfos.getInfoDraftorgid() != null) {
                predicates.add(builder.like(root.get("infoDraftorgid" ).as(String.class), "%" + cmInfos.getInfoDraftorgid() + "%" ));
            }
            if (cmInfos.getInfoDraftorgname() != null) {
                predicates.add(builder.like(root.get("infoDraftorgname" ).as(String.class), "%" + cmInfos.getInfoDraftorgname() + "%" ));
            }
            if (cmInfos.getInfoDrafttime() != null) {
                predicates.add(builder.like(root.get("infoDrafttime" ).as(String.class), "%" + cmInfos.getInfoDrafttime() + "%" ));
            }
            if (cmInfos.getInfoPublishtime() != null) {
                predicates.add(builder.like(root.get("infoPublishtime" ).as(String.class), "%" + cmInfos.getInfoPublishtime() + "%" ));
            }
            if (cmInfos.getInfoState() != null) {
                predicates.add(builder.like(root.get("infoState" ).as(String.class), "%" + cmInfos.getInfoState() + "%" ));
            }
            if (cmInfos.getInfoDesc() != null) {
                predicates.add(builder.like(root.get("infoDesc" ).as(String.class), "%" + cmInfos.getInfoDesc() + "%" ));
            }
            if (cmInfos.getInfoThumbpicpath() != null) {
                predicates.add(builder.like(root.get("infoThumbpicpath" ).as(String.class), "%" + cmInfos.getInfoThumbpicpath() + "%" ));
            }
            if (cmInfos.getInfoFilenum() != null) {
                predicates.add(builder.like(root.get("infoFilenum" ).as(String.class), "%" + cmInfos.getInfoFilenum() + "%" ));
            }
            if (cmInfos.getInfoCode() != null) {
                predicates.add(builder.like(root.get("infoCode" ).as(String.class), "%" + cmInfos.getInfoCode() + "%" ));
            }
            if (cmInfos.getInfoAuthor() != null) {
                predicates.add(builder.like(root.get("infoAuthor" ).as(String.class), "%" + cmInfos.getInfoAuthor() + "%" ));
            }
            if (cmInfos.getInfoDate() != null) {
                predicates.add(builder.like(root.get("infoDate" ).as(String.class), "%" + cmInfos.getInfoDate() + "%" ));
            }
            if (cmInfos.getInfoPath() != null) {
                predicates.add(builder.like(root.get("infoPath" ).as(String.class), "%" + cmInfos.getInfoPath() + "%" ));
            }
            if (cmInfos.getClId() != null) {
                predicates.add(builder.like(root.get("clId" ).as(String.class), "%" + cmInfos.getClId() + "%" ));
            }
            if (cmInfos.getInfoForwardchannels() != null) {
                predicates.add(builder.like(root.get("infoForwardchannels" ).as(String.class), "%" + cmInfos.getInfoForwardchannels() + "%" ));
            }
            if (cmInfos.getInfoDeleteuserid() != null) {
                predicates.add(builder.like(root.get("infoDeleteuserid" ).as(String.class), "%" + cmInfos.getInfoDeleteuserid() + "%" ));
            }
            if (cmInfos.getInfoDeletusername() != null) {
                predicates.add(builder.like(root.get("infoDeletusername" ).as(String.class), "%" + cmInfos.getInfoDeletusername() + "%" ));
            }
            if (cmInfos.getInfoDeletetime() != null) {
                predicates.add(builder.like(root.get("infoDeletetime" ).as(String.class), "%" + cmInfos.getInfoDeletetime() + "%" ));
            }
            if (cmInfos.getInfoPublishuserid() != null) {
                predicates.add(builder.like(root.get("infoPublishuserid" ).as(String.class), "%" + cmInfos.getInfoPublishuserid() + "%" ));
            }
            if (cmInfos.getInfoPublishusername() != null) {
                predicates.add(builder.like(root.get("infoPublishusername" ).as(String.class), "%" + cmInfos.getInfoPublishusername() + "%" ));
            }
            if (cmInfos.getInfoPublishdate() != null) {
                predicates.add(builder.like(root.get("infoPublishdate" ).as(String.class), "%" + cmInfos.getInfoPublishdate() + "%" ));
            }
            if (cmInfos.getInfoIsrepeat() != null) {
                predicates.add(builder.like(root.get("infoIsrepeat" ).as(String.class), "%" + cmInfos.getInfoIsrepeat() + "%" ));
            }
            if (cmInfos.getInfoPreinfoid() != null) {
                predicates.add(builder.like(root.get("infoPreinfoid" ).as(String.class), "%" + cmInfos.getInfoPreinfoid() + "%" ));
            }
            if (cmInfos.getInfoType() != null) {
                predicates.add(builder.like(root.get("infoType" ).as(String.class), "%" + cmInfos.getInfoType() + "%" ));
            }
            if (cmInfos.getClName() != null) {
                predicates.add(builder.like(root.get("clName" ).as(String.class), "%" + cmInfos.getClName() + "%" ));
            }
            if (cmInfos.getInfoPublishdesc() != null) {
                predicates.add(builder.like(root.get("infoPublishdesc" ).as(String.class), "%" + cmInfos.getInfoPublishdesc() + "%" ));
            }
            if (cmInfos.getInfoReturnuserid() != null) {
                predicates.add(builder.like(root.get("infoReturnuserid" ).as(String.class), "%" + cmInfos.getInfoReturnuserid() + "%" ));
            }
            if (cmInfos.getInfoReturnusername() != null) {
                predicates.add(builder.like(root.get("infoReturnusername" ).as(String.class), "%" + cmInfos.getInfoReturnusername() + "%" ));
            }
            if (cmInfos.getInfoReturntime() != null) {
                predicates.add(builder.like(root.get("infoReturntime" ).as(String.class), "%" + cmInfos.getInfoReturntime() + "%" ));
            }
            if (cmInfos.getInfoReturnreason() != null) {
                predicates.add(builder.like(root.get("infoReturnreason" ).as(String.class), "%" + cmInfos.getInfoReturnreason() + "%" ));
            }
            if (cmInfos.getInfoIsforward() != null) {
                predicates.add(builder.like(root.get("infoIsforward" ).as(String.class), "%" + cmInfos.getInfoIsforward() + "%" ));
            }
            if (cmInfos.getInfoMainid() != null) {
                predicates.add(builder.like(root.get("infoMainid" ).as(String.class), "%" + cmInfos.getInfoMainid() + "%" ));
            }
            if (cmInfos.getInfoIsread() != null) {
                predicates.add(builder.like(root.get("infoIsread" ).as(String.class), "%" + cmInfos.getInfoIsread() + "%" ));
            }
            if (cmInfos.getInfoContent() != null) {
                predicates.add(builder.like(root.get("infoContent" ).as(String.class), "%" + cmInfos.getInfoContent() + "%" ));
            }
            if (cmInfos.getInfoSource() != null) {
                predicates.add(builder.like(root.get("infoSource" ).as(String.class), "%" + cmInfos.getInfoSource() + "%" ));
            }
            if (cmInfos.getSiteId() != null) {
                predicates.add(builder.like(root.get("siteId" ).as(String.class), "%" + cmInfos.getSiteId() + "%" ));
            }
            if (cmInfos.getInfoIsreprint() != null) {
                predicates.add(builder.like(root.get("infoIsreprint" ).as(String.class), "%" + cmInfos.getInfoIsreprint() + "%" ));
            }
            if (cmInfos.getInfoDraftdate() != null) {
                predicates.add(builder.like(root.get("infoDraftdate" ).as(String.class), "%" + cmInfos.getInfoDraftdate() + "%" ));
            }
            if (cmInfos.getInfoDeletedate() != null) {
                predicates.add(builder.like(root.get("infoDeletedate" ).as(String.class), "%" + cmInfos.getInfoDeletedate() + "%" ));
            }
            if (cmInfos.getInfoReturndate() != null) {
                predicates.add(builder.like(root.get("infoReturndate" ).as(String.class), "%" + cmInfos.getInfoReturndate() + "%" ));
            }
            if (cmInfos.getInfoApprovedate() != null) {
                predicates.add(builder.like(root.get("infoApprovedate" ).as(String.class), "%" + cmInfos.getInfoApprovedate() + "%" ));
            }
            if (cmInfos.getInfoApprovetime() != null) {
                predicates.add(builder.like(root.get("infoApprovetime" ).as(String.class), "%" + cmInfos.getInfoApprovetime() + "%" ));
            }
            if (cmInfos.getInfoApproveuserid() != null) {
                predicates.add(builder.like(root.get("infoApproveuserid" ).as(String.class), "%" + cmInfos.getInfoApproveuserid() + "%" ));
            }
            if (cmInfos.getInfoApproveusername() != null) {
                predicates.add(builder.like(root.get("infoApproveusername" ).as(String.class), "%" + cmInfos.getInfoApproveusername() + "%" ));
            }
            if (cmInfos.getInfoApprovememo() != null) {
                predicates.add(builder.like(root.get("infoApprovememo" ).as(String.class), "%" + cmInfos.getInfoApprovememo() + "%" ));
            }
            if (cmInfos.getSiteName() != null) {
                predicates.add(builder.like(root.get("siteName" ).as(String.class), "%" + cmInfos.getSiteName() + "%" ));
            }
            if (cmInfos.getInfoSubhead() != null) {
                predicates.add(builder.like(root.get("infoSubhead" ).as(String.class), "%" + cmInfos.getInfoSubhead() + "%" ));
            }
            if (cmInfos.getInfoMode() != null) {
                predicates.add(builder.like(root.get("infoMode" ).as(String.class), "%" + cmInfos.getInfoMode() + "%" ));
            }
            if (cmInfos.getInfoGoodnum() != null) {
                predicates.add(builder.like(root.get("infoGoodnum" ).as(String.class), "%" + cmInfos.getInfoGoodnum() + "%" ));
            }
            if (cmInfos.getInfoPush() != null) {
                predicates.add(builder.like(root.get("infoPush" ).as(String.class), "%" + cmInfos.getInfoPush() + "%" ));
            }
            if (cmInfos.getInfoIslink() != null) {
                predicates.add(builder.like(root.get("infoIslink" ).as(String.class), "%" + cmInfos.getInfoIslink() + "%" ));
            }
            if (cmInfos.getInfoLinkurl() != null) {
                predicates.add(builder.like(root.get("infoLinkurl" ).as(String.class), "%" + cmInfos.getInfoLinkurl() + "%" ));
            }
            if (cmInfos.getInfoConten() != null) {
                predicates.add(builder.like(root.get("infoConten" ).as(String.class), "%" + cmInfos.getInfoConten() + "%" ));
            }
            if (cmInfos.getInfoDeleteusername() != null) {
                predicates.add(builder.like(root.get("infoDeleteusername" ).as(String.class), "%" + cmInfos.getInfoDeleteusername() + "%" ));
            }
            Predicate[] p = new Predicate[predicates.size()];
            return query.where(builder.and(predicates.toArray(p))).getRestriction();
        };
    }

}
